"""
运行程序，打开浏览器访问以下url：
http://127.0.0.1:8080

"""
import socket

HOST = ''
PORT = 8080

sk = socket.socket()
sk.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sk.bind((HOST, PORT))
sk.listen(1)
print('Serving HTTP on port %s ...' % PORT)

while True:
    client_connection, client_address = sk.accept()
    request = client_connection.recv(1024)
    print(request.decode("utf-8"))
    # response要符合http响应报文头格式
    response = """\
HTTP/1.1 200 OK

welcome to iamlfy.com!
"""
    client_connection.sendall(response.encode('utf-8'))
    client_connection.close()
